﻿#region Copyright Notice
// This file is part of GestionPedago.
// <description>
// Copyright (C) 2012 ENI Ecole Informatique
// 
// GestionPedago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// <program> is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using GestionPedago.EntityContext;
using GestionPedago.Services.Framework;
using GestionPedago.Services.ES.Modele;

namespace GestionPedago.Services.Mapping
{
    /// <summary>
    /// Classe de mapping Entity<->ES de l'objet PlanningIndividuelFormation
    /// </summary>
    public class PlanningIndividuelFormationMappeur : IMappeur<PlanningIndividuelFormation, PlanningIndividuelFormationES>
    {
        /// <summary>
        /// Constructeur
        /// </summary>
        public PlanningIndividuelFormationMappeur() { }

        /// <summary>
        /// Mapping Entity -> ES
        /// </summary>
        /// <param name="entity">L'entity à mapper</param>
        /// <returns>L'ES obtenu</returns>
        public PlanningIndividuelFormationES Entity2ES(PlanningIndividuelFormation entity)
        {
            PlanningIndividuelFormationES retour = new PlanningIndividuelFormationES();
            retour.CodePlanning = entity.CodePlanning;
            retour.CodeStagiaire = entity.CodeStagiaire;
            retour.DateInscription = entity.DateInscription;
            retour.DateCreation = entity.DateCreation;
            retour.CodeTypeProfil = entity.CodeTypeProfil;
            retour.CodeFormation = entity.CodeFormation;
            retour.CodePromotion = entity.CodePromotion;
            retour.DateModif = entity.DateModif;
            retour.NumLien = entity.NumLien;
            retour.Formation = new FormationMappeur().Entity2ES(entity.Formation);
            retour.ListePlanningECFDetail = new List<PlanningECFDetailES>();
            foreach (PlanningECFDetail ped in entity.PlanningECFDetail)
            {
                retour.ListePlanningECFDetail.Add(new PlanningECFDetailMappeur().Entity2ES(ped));
            }
            retour.ListePlanningIndividuelDetail = new List<PlanningIndividuelDetailES>();
            foreach (PlanningIndividuelDetail pid in entity.PlanningIndividuelDetail)
            {
                retour.ListePlanningIndividuelDetail.Add(new PlanningIndividuelDetailMappeur().Entity2ES(pid));
            }
            //TODO implémenter mapping Entity<->ES manuellement ! : Promotion
            //TODO implémenter mapping Entity<->ES manuellement ! : Stagiaire
            //TODO implémenter mapping Entity<->ES manuellement ! : StagiaireParEntreprise
            //TODO implémenter mapping Entity<->ES manuellement ! : TypeProfil
            //TODO implémenter mapping Entity<->ES manuellement ! : PlanningTitreDetail
            return retour;
        }

        /// <summary>
        /// Mapping ES -> Entity
        /// </summary>
        /// <param name="es">L'ES à mapper</param>
        /// <returns>L'entity obtenu</returns>
        public PlanningIndividuelFormation ES2Entity(PlanningIndividuelFormationES es)
        {
            PlanningIndividuelFormation retour = new PlanningIndividuelFormation();
            retour.CodePlanning = es.CodePlanning;
            retour.CodeStagiaire = es.CodeStagiaire;
            retour.DateInscription = es.DateInscription;
            retour.DateCreation = es.DateCreation;
            retour.CodeTypeProfil = es.CodeTypeProfil;
            retour.CodeFormation = es.CodeFormation;
            retour.CodePromotion = es.CodePromotion;
            retour.DateModif = es.DateModif;
            retour.NumLien = es.NumLien;
            retour.Formation = new FormationMappeur().ES2Entity(es.Formation);
            //TODO implémenter mapping Entity<->ES manuellement ! : PlanningECFDetail
            //TODO implémenter mapping Entity<->ES manuellement ! : PlanningIndividuelDetail
            //TODO implémenter mapping Entity<->ES manuellement ! : Promotion
            //TODO implémenter mapping Entity<->ES manuellement ! : Stagiaire
            //TODO implémenter mapping Entity<->ES manuellement ! : StagiaireParEntreprise
            //TODO implémenter mapping Entity<->ES manuellement ! : TypeProfil
            //TODO implémenter mapping Entity<->ES manuellement ! : PlanningTitreDetail
            if (!EntityStateChecker.IsDetached(retour))
            {
                EntityConnection.GetContext().PlanningIndividuelFormation.ApplyCurrentValues(retour);
            }
            else
            {
                EntityConnection.GetContext().PlanningIndividuelFormation.Attach(retour);
            }
            return retour;
        }
    }
}
